package com.zoke.support.base;

import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;

import com.zoke.support.R;
import com.zoke.support.indicator.lib.Indicator;
import com.zoke.support.indicator.lib.IndicatorViewPager;
import com.zoke.support.indicator.lib.IndicatorViewPager.IndicatorPagerAdapter;
import com.zoke.support.indicator.lib.IndicatorViewPager.IndicatorViewPagerAdapter;

/**
 * 欢迎页
 * 
 * @author JackWu
 * 
 */
public class BaseGuideActivity extends BaseActivity {
	// 指示器与ViewPager联合使用
	private IndicatorViewPager indicatorViewPager;
	private LayoutInflater inflate;
	protected int[] mImages;
	public static final String GUIDE_IMAGES = "guide_images";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_guide);
		ViewPager viewPager = (ViewPager) findViewById(R.id.guide_viewPager);
		Indicator indicator = (Indicator) findViewById(R.id.guide_indicator);
		indicatorViewPager = new IndicatorViewPager(indicator, viewPager);
		inflate = LayoutInflater.from(getApplicationContext());
		mImages = getIntent().getExtras().getIntArray(GUIDE_IMAGES);
		indicatorViewPager.setAdapter(adapter);
	}

	/** 默认的Adapter **/
	private IndicatorPagerAdapter adapter = new IndicatorViewPagerAdapter() {

		@Override
		public View getViewForTab(int position, View convertView,
				ViewGroup container) {
			if (convertView == null) {
				convertView = inflate.inflate(R.layout.guide_point, container,
						false);
			}
			return convertView;
		}

		@Override
		public View getViewForPage(int position, View convertView,
				ViewGroup container) {
			if (convertView == null) {
				//
				convertView = new View(getApplicationContext());
				convertView.setLayoutParams(new LayoutParams(
						LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
			}
			convertView.setBackgroundResource(mImages[position]);
			return convertView;
		}

		@Override
		public int getCount() {
			return mImages.length;
		}
	};

}
